<template>
    <div id="app">
        <keep-alive>
            <router-view />
        </keep-alive>
        <div class="goBack" @click="goBackFS()">返回</div>
        <AddUserDialog ref="AddUserDialog" />
        <UserListDialog ref="UserListDialog" />
    </div>
</template>

<script>
/* eslint-disable */
import { mapActions } from 'vuex';
import AddUserDialog from '@/components/addUserDialog/addUserDialog.vue';
import UserListDialog from '@/components/userListDialog/userListDialog.vue';

export default {
    name: 'app',
    components: {
        AddUserDialog,
        UserListDialog,
    },
    data() {
        return {};
    },
    mounted() {
        this.initialize();
        // this.$bus.emit('APP_Dialog', {
        //     name: '弹窗名',
        //     dataForm: '弹窗数据'
        // })
        this.$bus.on('APP_Dialog', (data) => {
            switch (data.name) {
                case 'AddUserDialog':
                    this.$refs.AddUserDialog &&
                        this.$refs.AddUserDialog.openFS(data.dataForm);
                    break;
                case 'UserListDialog':
                    this.$refs.UserListDialog &&
                        this.$refs.UserListDialog.openFS(data.dataForm);
                    break;
            }
        });
    },
    methods: {
        ...mapActions(['GetUserInfo']),
        goBackFS() {
            // this.$router.go(-1); //返回上一层
            this.$router.push({
                path: '/',
                params: {
                    id: 222,
                },
            });
        },
        initialize() {
            this.GetUserInfo().then((result) => {
                console.log(result);
                switch (result.userAction) {
                    case 0: // 没有用户，打开创建用户弹窗
                        this.$refs.AddUserDialog &&
                            this.$refs.AddUserDialog.openFS();
                        break;
                    case 1: // 有用户但是没有选中的用户
                        this.$refs.UserListDialog &&
                            this.$refs.UserListDialog.openFS();
                        break;
                    // case 2: // 有用户且有选中的用户
                    //     break;
                }
            });
        },
    },
};
</script>

<style lang="scss">
@import '@/plugins/element.scss';

@media (prefers-color-scheme: dark) {
}
@media (prefers-color-scheme: light) {
}

#app {
    width: 100%;
    height: 100%;
    font-family: 'Avenir', Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
    .goBack{
        position: absolute;
        top: 16px;
        left: 16px;
        z-index: 10000;
    }
}
</style>
